package EjemploEventos;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

public class ClaPanel extends JPanel implements MouseListener {

	private int x, y;

	private int iAncho;

	public ClaPanel() {

		iAncho = 50;

		setSize(500, 500);

		this.addMouseListener(this);

	}

	public void setiAncho(int iAncho) {

		this.iAncho = iAncho;

	}

	public void paintComponent(Graphics g) {

		super.paintComponent(g);

		g.setColor(Color.gray);

		g.fillRect(0, 0, 500, 500);

		g.setColor(Color.RED);

		g.drawRect(x, y, iAncho, iAncho);

	}

	@Override
	public void mouseClicked(MouseEvent e) {

		x = e.getX();

		y = e.getY();

		this.repaint();

	}

	@Override
	public void mouseEntered(MouseEvent e) {

	}

	@Override
	public void mouseExited(MouseEvent e) {

	}

	@Override
	public void mousePressed(MouseEvent e) {

	}

	@Override
	public void mouseReleased(MouseEvent e) {

	}

}